<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="课程id" prop="classId">-->
<!--        <el-input-->
<!--          v-model="queryParams.classId"-->
<!--          placeholder="请输入课程id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['class:class_choose:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['class:class_choose:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['class:class_choose:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['class:class_choose:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="class_chooseList" @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" align="center" width="50"/>
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="课程" align="center" prop="class_name" />
      <el-table-column label="教师" align="center" prop="teacher_name" />
      <el-table-column label="已获学分" align="center" prop="class_score" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            v-hasPermi="['student:study']"-->
<!--            @click="studyWay(scope.row)"-->
<!--          >个性化学习</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['student:study']"
            @click="study(scope.row)"
          >学习</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['student:pig']"
            @click="showpic(scope.row)"
          >图谱学习</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="testClass(scope.row)"
            v-hasPermi="['student:test']"
          >测试</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['student:out']"
          >退课</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改class_choose对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="课程id" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入课程id" />
        </el-form-item>
        <el-form-item label="已获学分" prop="classScore">
          <el-input v-model="form.classScore" placeholder="请输入已获学分" />
        </el-form-item>
<!--        <el-form-item label="学习进度" prop="classProgress">-->
<!--          <el-input v-model="form.classProgress" placeholder="请输入学习进度" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listClass_choose_myself, getClass_choose, out_class, addClass_choose, updateClass_choose } from "@/api/class/class_choose"

export default {
  name: "Class_choose",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // class_choose表格数据
      class_chooseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        classId: null,
        classScore: null,
        classProgress: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "学生id不能为空", trigger: "blur" }
        ],
        classId: [
          { required: true, message: "课程id不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 测试考试操作 */
    testClass(row) {
      this.$router.push({ path: '/class/class_choose/test', query: { classId: row.class_id } });
    },

    showpic(row) {
      this.$router.push({ path: '/class/class_choose/showpic', query: { classId: row.class_id } });
    },

    study(row) {
      this.$router.push({ path: '/class/class_choose/study', query: { classId: row.class_id } });
    },

    studyWay(row) {
      this.$router.push({ path: '/class/class_choose/studyWay', query: { classId: row.class_id } });
    },
    /** 查询class_choose列表 */
    getList() {
      this.loading = true
      listClass_choose_myself().then(response => {
        this.class_chooseList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        classId: null,
        classScore: null,
        classProgress: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加class_choose"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      getClass_choose(row.id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改class_choose"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateClass_choose(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addClass_choose(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    /** 退课 */
    handleDelete(row) {
      this.$modal.confirm('是否确认退出"' + row.class_name + '"的课程？').then(function() {
        return out_class(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("退出成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('class/class_choose/export', {
        ...this.queryParams
      }, `class_choose_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
